import math

st = input()
a = st.split()
n = ""
c = 0
for word in a:
    if word == "zero":
        n += "0"
        c += 1
    elif word == "one":
        n += "1"
        c += 1
    elif word == "two":
        n += "2"
        c += 1
    elif word == "three":
        n += "3"
        c += 1
    elif word == "four":
        n += "4"
        c += 1
    elif word == "five":
        n += "5"
        c += 1
    elif word == "six":
        n += "6"
        c += 1
    elif word == "seven":
        n += "7"
        c += 1
    elif word == "eight":
        n += "8"
        c += 1
    elif word == "nine":
        n += "9"
        c += 1
    else:
        break

if c == 3:
    num = int(n)
    it = 0
    flag = True
    while flag:
        nmin = num - it
        nmax = num + it
        for i in range(2, int(math.sqrt(nmin)) + 1):
            if nmin % i == 0:
                break
            if i + 1 > math.sqrt(nmin):
                print(nmin)
                flag = False
        for i in range(2, int(math.sqrt(nmax)) + 1):
            if nmax % i == 0:
                break
            if i + 1 > math.sqrt(nmax):
                if flag:
                    print(nmax)
                    flag = False
        it += 1
else:
    print("Wrong input")
